package com.hkts.naturalgasauthentication.security;

import com.hkts.naturalgasauthentication.base.dao.HontUserDao;
import com.hkts.naturalgasauthentication.base.entity.User;
import com.hkts.naturalgasauthentication.common.Exception.BlankException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private HontUserDao hontUserDao;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User hontUserByUserName = hontUserDao.findByUserName(s);
        if (hontUserByUserName.getStatus() == -1) {
            throw new BlankException("被拉黑！");
        }

        return new SecurityUserDetails(hontUserByUserName);
    }
}
